package vip.george.sentinel2.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vip.george.common.entity.ScUser;
import vip.george.sentinel2.service.PayService;
import vip.george.sentinel2.service.feign.FeignUserClient;


/**
 * @author george
 * @since 2023/7/10
 * <p></p>
 */
@Service
public class PayServiceImpl implements PayService  {

    @Autowired
    private FeignUserClient feignUserService;

    @Override
    @SentinelResource(value = "payService",blockHandler = "payServiceBlockHandler")
    public String pay(Long userId) {
        ScUser scUser = feignUserService.queryUser(userId).getDataAndCheckSuccess();
        return "pay success";
    }

    public String payServiceBlockHandler(Long userId, BlockException ex) {
        ex.printStackTrace();
        return "支付失败，被限流";
    }



}
